package com.infore.airsupervise.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.infore.airsupervise.R;
import com.infore.airsupervise.app.Constants;
import com.infore.airsupervise.bean.StationDetailE;
import com.infore.airsupervise.biz.StationDetailBiz;
import com.infore.airsupervise.biz.impl.StationDetailBizImpl;
import com.infore.airsupervise.http.BaseResponse;
import com.infore.airsupervise.http.OnServerResponseListener;
import com.infore.airsupervise.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;

/**
 * 站点详情界面
 * （从AQI界面跳转至此）
 */
public class StationDetailActivity extends BaseTitleBarActivity {

    @BindView(R.id.tv_station_code)
    TextView tvStationCode;
    @BindView(R.id.tv_station_name)
    TextView tvStationName;
    @BindView(R.id.tv_station_type)
    TextView tvStationType;
    @BindView(R.id.tv_station_source_type)
    TextView tvStationSourceType;
    @BindView(R.id.tv_station_address)
    TextView tvStationAddress;
    @BindView(R.id.tv_station_remark)
    TextView tvStationRemark;
    @BindView(R.id.tv_station_gridLine)
    TextView tvStationGridLine;
    @BindView(R.id.tv_station_psonGrid)
    TextView tvStationPsonGrid;
    @BindView(R.id.tv_station_psonPhone)
    TextView tvStationPsonPhone;
    @BindView(R.id.tv_station_psonGrid_up)
    TextView tvStationPsonGridUp;
    @BindView(R.id.tv_station_psonPhone_up)
    TextView tvStationPsonPhoneUp;
    @BindView(R.id.tv_station_remarkGrid)
    TextView tvStationRemarkGrid;

    private StationDetailBiz detailBiz;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent it = getIntent();
        detailBiz = new StationDetailBizImpl();
        if(it!=null){
            //获取mn号
            String mn=it.getStringExtra(Constants.INTENT_STR_KEY);
            //根据mn号 获取站点信息
            Call<BaseResponse> call = detailBiz.sendStationDetailRequest(mn,listener);
            requests.add(call);
        }
        setContentView(R.layout.activity_station_detail);
        ButterKnife.bind(this);
        rightMenu.setVisibility(View.INVISIBLE);
    }

    /**
     * 网络请求 回调方法
     */
    private OnServerResponseListener<StationDetailE> listener = new OnServerResponseListener<StationDetailE>() {
        @Override
        public void onSucceed(StationDetailE result, String desc) {
            if(result == null){
                return ;
            }
            setStationDetailUI(result);
        }

        @Override
        public void onFailed(int errorCode, String title, String desc) {
            ToastUtil.showShort(ctx,title+" : "+desc);
        }
    };


    /**
     * 加载站点详情
     */
    private void setStationDetailUI(StationDetailE detailE){
        //mn
        tvStationCode.setText(detailE.getMn());
        //站点名ming
        tvStationName.setText(detailE.getName());
        title.setText(detailE.getName());
        //类型
        tvStationType.setText(detailE.getStationType());
        tvStationSourceType.setText(detailE.getStationSourceType());
        //地址
        tvStationAddress.setText(detailE.getAddress());
        //备注
        tvStationRemark.setText(detailE.getStationRemark());
        tvStationRemarkGrid.setText(detailE.getGridRemark());
        //网格员
        tvStationPsonGrid.setText(detailE.getGridPson());
        tvStationPsonPhone.setText(detailE.getGridPsonPhone());
        tvStationPsonGridUp.setText(detailE.getUpGridPson());
        tvStationPsonPhoneUp.setText(detailE.getUpGridPsonPhone());
        tvStationGridLine.setText(detailE.getGrid());
    }
}
